﻿using System;
using System.Collections.Generic;
using System.Text;

using Vitruvian.Serialization;
using Vitruvian.Logging;
using Vitruvian.Testing;

namespace SpotItComponents
{
    [ContainsTests("Components.CatgeoryStuff")]
    [OptimisticSerialization]
    public class Category : Component
    {
        #region Private Data Member
        private static Logger logger = Logger.GetLogger(typeof(Category));
        #endregion

        #region Public Properties
        public string Label { get; set; }
        public Category Parent { get; set; }
        #endregion

        #region Constructors
        public Category() { }
        public Category(string label)
        {
            Label = label;
            Parent = null;

            logger.DebugFormat("Created a new category {0}, id={1}", Label, Id);
        }
        public Category(string label, Category parent)
        {
            Label = label;
            Parent = parent;

            logger.DebugFormat("Created a new sub-category {0}, id={1}", Label, Id);
        }
        #endregion


        #region Unit Test Cases
#if (DEBUG)
        [Test(1)]
        private void Test_Symbol_Constructors_Properties_and_Compare()
        {
            Category c1 = new Category("Test Category A");
            Assert.IsNotEqual(Guid.Empty, c1.Id);
            Assert.IsEqual("Test Category A", c1.Label);
            Assert.IsNull(c1.Parent);

            Category c2 = new Category("Test Category B");
            Assert.IsNotEqual(Guid.Empty, c2.Id);
            Assert.IsEqual("Test Category B", c2.Label);
            Assert.IsNull(c2.Parent);

            Category c3 = new Category("Test Category A.1", c1);
            Assert.IsNotEqual(Guid.Empty, c3.Id);
            Assert.IsEqual("Test Category A.1", c3.Label);
            Assert.IsNotNull(c3.Parent);
            Assert.IsEqual(c1.Id, c3.Parent.Id);

            Category c4 = new Category("Test Category A.2", c1);
            Assert.IsNotEqual(Guid.Empty, c4.Id);
            Assert.IsEqual("Test Category A.2", c4.Label);
            Assert.IsNotNull(c4.Parent);
            Assert.IsEqual(c1.Id, c4.Parent.Id);

            Assert.IsEqual(c1, c1);
            Assert.IsNotEqual(c1, c2);
            Assert.IsNotEqual(c2, c1);

            Category c5 = new Category();
            c5.Id = c1.Id;
            Assert.IsEqual(c1, c5);
            Assert.IsTrue(c1.Equals(c5));
        }

#endif
        #endregion

    }
}
